package com.guigu.basedservice.service.impl;

import com.guigu.basedservice.entity.BaseCarTypePartsSku;
import com.guigu.basedservice.mapper.BaseCarTypePartsSkuMapper;
import com.guigu.basedservice.service.BaseCarTypePartsSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.basedservice.utils.UniqueIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 车型配件关联表 服务实现类
 * </p> *
 * @author Heyuhang
 * @since 2024-09-20
 */
@Service
public class BaseCarTypePartsSkuServiceImpl extends ServiceImpl<BaseCarTypePartsSkuMapper, BaseCarTypePartsSku> implements BaseCarTypePartsSkuService {

    @Autowired(required = false)
    private BaseCarTypePartsSkuMapper baseCarTypePartsSkuMapper;

    @Autowired(required = false)
    private UniqueIdGenerator uniqueIdGenerator;

    @Override
    public boolean insertBaseCarTypePartsSku(BaseCarTypePartsSku baseCarTypePartsSku) {
        // 获取 carTypeUuid 和 partUuid 列表
        String ctpUuid = UniqueIdGenerator.generateUniqueId();
        int version = 0;
        String carTypeUuid = baseCarTypePartsSku.getCarTypeUuid();
        List<String> partUuidList = baseCarTypePartsSku.getPartUuid();

        // 调用 MyBatis Mapper 执行批量插入
        int rowsInserted = baseCarTypePartsSkuMapper.insertCarTypePart(ctpUuid, carTypeUuid, partUuidList, version);

        // 检查是否成功插入
        return rowsInserted > 0;
    }
}
